<template>
  <!-- 账单生成日每月 -->
  <div>
    <el-input
      :placeholder="$t('请输入账单生成日')"
      :disabled="readonly"
      @change="changeData"
      v-model="checkedData"
    ></el-input>
  </div>
</template>
<script>
import nonStandardService from '@/services/nonStandardService'
import eventBus from '@/assets/utils/eventBus.js'
export default {
  name: 'billGenDay',
  props: {
    detail: {
      type: Object,
      default: () => {
        return {}
      },
    },
    value: [Object, String],
    disabled: Boolean,
    parameter: {
      type: Object,
      default: () => {
        return {}
      },
    },
    data: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      checkedData: '',
      rules: {
        checkedData: [
          {
            required: this.parameter.state === 4,
            validator: (rule, value, callback) => {
              if (
                this.checkedData &&
                (!Number.isInteger(Number(this.checkedData)) ||
                  this.checkedData > 28)
              ) {
                callback(new Error(this.$t('请输入1-28的整数')))
                return
              }
              if (!this.checkedData && this.parameter.state === 4) {
                callback(new Error(this.$t('请输入账单生成日')))
                return
              } else {
                callback()
                return
              }
            },
            trigger: 'blur',
          },
        ],
      },
      readonly: false,
    }
  },
  created() {
    this.readonly = Boolean(this.$route.query.readonly)
    if (this.value) {
      this.setData()
    }
    this.$emit('setrules', this.parameter, {
      [this.parameter.parameterNumber]: this.rules.checkedData,
    })
  },
  methods: {
    changeData() {
      this.$emit('input', String(this.checkedData))
    },
    setData() {
      this.checkedData = JSON.parse(this.value).value
        ? JSON.parse(this.value).value
        : ''
    },
    getData() {
      return {
        value: this.checkedData,
      }
    },
  },
}
</script>
